//
//  calculatorViewController.m
//  calculator
//
//  Created by Will Martin on 5/4/10.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//
//Comit test with deleting build folder - Will

#import "calculatorViewController.h"

@implementation calculatorViewController

-(calcBrain *)brain{
	if(!brain) brain = [[calcBrain alloc] init];
	return brain;
}

-(IBAction)digitPressed:(UIButton *)sender{
	NSString *digit = [[sender titleLabel] text];
	if(userIsInTheMiddleOfTypingANumber){
		[display setText:[[display text] stringByAppendingString:digit]];
	}
	else {
		[display setText:digit];
		userIsInTheMiddleOfTypingANumber = YES;
	}

}

-(IBAction)operationPressed:(UIButton *)sender{
	if(userIsInTheMiddleOfTypingANumber){
		[[self brain] setOperand:[[display text] doubleValue]];
		userIsInTheMiddleOfTypingANumber = NO;
		}
	NSString *operation = [[sender titleLabel] text];
	double result = [[self brain] performOperation:operation];
	[display setText:[NSString stringWithFormat:@"%g",result]];
}

@end
